#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;

const int MAXN = 4e5 + 5;
const int MOD = 1e9 + 7;

int n, a, b, c, d;

struct Edge {
    int to, next, w;
} e[MAXN << 1];

int head[MAXN], idx = 1;
bool vis[MAXN];
void add_edge(int u, int v, int w) {
    e[idx].to = v;
    e[idx].next = head[u];
    e[idx].w = w;
    head[u] = idx++;
}
void clear_graph() {
    memset(head, -1, sizeof(head));
    memset(e, 0, sizeof(e));
    idx = 1;
}

ll cur = -1, res = -1;

void dfs(int u, int fa = -1, ll d = 0) {
    if (d > res) res = d, cur = u;

    for (int i = head[u]; ~i; i = e[i].next) {
        int j = e[i].to, w = e[i].w;
        if (j != fa)
            dfs(j, u, d + w);
    }
}

vector<ll> dijkstra(int st) {
    vector<ll> d(n * 2 + 1, INT64_MAX);
    memset(vis, false, sizeof(vis));

    priority_queue<pli, vector<pli>, greater<pli>> h;

    h.push({ 0, st });
    d[st] = 0;

    while (!h.empty()) {
        int u = h.top().second;
        h.pop();

        if (!vis[u]) {
            vis[u] = true;
            for (int i = head[u]; ~i; i = e[i].next) {
                int j = e[i].to, w = e[i].w;
                if (d[j] > d[u] + w) {
                    d[j] = d[u] + w;
                    h.push({ d[j], j });
                }
            }
        }
    }

    return d;
}

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> n;
    clear_graph();
    for (int i = 1; i <= n - 1; i++) {
        cin >> a >> b >> c;
        add_edge(a, b, c), add_edge(b, a, c);
    }

    for (int i = 1; i <= n; i++) {
        cin >> d;
        add_edge(i, i + n, d), add_edge(i + n, i, d);
    }

    int ss, tt;
    dfs(1);
    ss = cur;
    dfs(cur);
    tt = cur;

    auto d1 = dijkstra(ss), d2 = dijkstra(tt);

    for (int i = 1; i <= n; i++) {
        ll temp = -1;
        if (i == ss - n) temp = d2[i];
        else if (i == tt - n) temp = d1[i];

        else temp = max(d1[i], d2[i]);
        cout << temp << endl;
    }
    return 0;
}